<?php
namespace App\Admin\Controllers;

use App\Models\Area;
use App\Models\HospitalAppoint;
use App\Models\HospitalAppointInterval;
use App\Models\Vaccine;
use Dcat\Admin\Admin;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ApiController  extends AdminController{


    public function city(Request $request)
    {
        $provinceId = $request->get('q');
    
        return Area::query()->where('parent_id', $provinceId)->get(['id', DB::raw('title as text')]);
    }

    public function appoint_time(Request $request)
    {
        $provinceId = $request->get('q');
        $hospitalAppoint = HospitalAppoint::query()
            ->where('type',$provinceId)
            ->where('hospital_id',Admin::user()->hospital_id)
            ->first();
    
        return HospitalAppointInterval::query()->where('hospital_appoint_id', $hospitalAppoint->id)->get(['id', DB::raw('start as text')]);
    }


}